package org.jeecg.modules.nikeProject.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.modules.nikeProject.entity.SportsProject;
import org.jeecg.modules.nikeProject.entity.vo.*;
import org.jeecg.modules.nikeProject.service.ISportsProjectService;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @Description: 案例评审-项目管理
 * @Author: jeecg-boot
 * @Date:   2024-12-05
 * @Version: V1.0
 */
@Api(tags="201-案例评审-项目管理")
@RestController
@RequestMapping("/sportsProject")
@Slf4j
public class SportsProjectController extends JeecgController<SportsProject, ISportsProjectService> {
	@Autowired
	private ISportsProjectService sportsProjectService;

	/**
	 *
	 * @param projectId
	 * @param step  1-个人基本信息，2-个人日常工作情况，3-案例申报，4-观察思考, 5-申报推荐人，6-上传资质文件 11-查看评审打分情况
	 * @param roleType   1-一线体育老师  2-推广大使  3-校长 4-体育教研员 5-评审 7-nike内部人员
	 * @param request
	 * @return
	 */
	@AutoLog(value = "案例评审-查询信息")
	@ApiOperation(value="案例评审-查询信息", notes="案例评审-查询信息")
	@GetMapping(value = "/queryInfoByCode")
	public Result<ProjectInfoVO> queryInfoByCode(@RequestParam(value = "projectId", required = false) String projectId,
												 @RequestParam(value = "step", required = false) String step,
												 @RequestParam(value = "roleType")String roleType,
												 HttpServletRequest request) {
		String username = JwtUtil.getUserNameByToken(request);
		return sportsProjectService.queryInfoByCode(projectId,step, username, roleType);
	}

	@AutoLog(value = "个人中心-申报管理案例列表")
	@ApiOperation(value="个人中心-申报管理案例列表", notes="个人中心-申报管理案例列表")
	@PostMapping(value = "/applicationList")
	public Result<?> applicationList(@RequestBody ReqListVO reqListVO,
												 HttpServletRequest request) {
		String username = JwtUtil.getUserNameByToken(request);
		return sportsProjectService.applicationList(reqListVO, username);
	}

	@AutoLog(value = "未提交资质文件的案例列表")
	@ApiOperation(value="未提交资质文件的案例列表", notes="未提交资质文件的案例列表")
	@GetMapping(value = "/getUnSubmitDocList")
	public Result<?> getUnSubmitDocList(@RequestParam(name="pageNo") Integer pageNo,
										@RequestParam(name="pageSize") Integer pageSize,
										HttpServletRequest request){
		return sportsProjectService.getUnSubmitDocList(pageNo, pageSize);
	}

	@AutoLog(value = "发送短信提醒用户补提交案例资质文件")
	@ApiOperation(value="发送短信提醒用户补提交案例资质文件", notes="发送短信提醒用户补提交案例资质文件")
	public Result<?> sendSMSToApply(@RequestParam(name="ids") List<String> ids){
		return sportsProjectService.sendSMSToApply(ids);
	}

	/**
	 *
	 * @param projectId
	 * @param reviewId   当角色类型为普通/专家评审时，需要带reviewId, NIKE专家团队不需要传
	 * @param roleType 1-填报人 5-评审 7-nike内部人员
	 * @param step
	 * @param request
	 * @param reviewType 1-普通专家评审后 2-资深专家评审后
	 * @return
	 */
	@AutoLog(value = "评审/nike团队查看项目详情接口")
	@ApiOperation(value="评审/nike团队查看项目详情接口", notes="评委/nike团队查看项目详情接口")
	@GetMapping(value = "/getProjectDetail")
	public Result<ProjectInfoVO> getProjectDetail(@RequestParam(value = "projectId") String projectId,
												  @RequestParam(value = "reviewId", required = false) String reviewId,
												  @RequestParam(value = "roleType") String roleType,
												  @RequestParam(value = "reviewType", required = false) String reviewType,
												  @RequestParam(value = "step") String step,
												  HttpServletRequest request){
		String username = JwtUtil.getUserNameByToken(request);
		if ("".equals(username)){
			return Result.error("无查看此信息的权限，请先登陆！");
		}
		return sportsProjectService.getProjectDetail(projectId, roleType, step, username, reviewId,reviewType);
	}

	@AutoLog(value = "案例填报提交")
	@ApiOperation(value="案例填报提交", notes="案例填报提交")
	@PostMapping(value = "/submit")
	public Result<?> submit(@RequestParam(value = "projectId", required = true) String projectId,
							HttpServletRequest request){
		 String username = JwtUtil.getUserNameByToken(request);
		return sportsProjectService.submit(projectId, username);
	}

	/**
	 * 分页列表查询
	 * firstAuditStatus 1-未初审，2-已通过，3-未通过 4-淘汰案例
	 * @param reqVO
	 * @return
	 */
	@AutoLog(value = "NIKE团队-案例初审列表")
	@ApiOperation(value="NIKE团队-案例初审列表", notes="NIKE团队-案例初审列表 firstAuditStatus：不填则代表全部， 1-未查重，2-已通过，4-淘汰案例")
	@PostMapping(value = "/list")
	public Result<RespFirstAuditListVO> list(@RequestBody ReqListVO reqVO) {
		return sportsProjectService.list(reqVO);
	}

	/**
	 * nike团队  查看待进行分配的案例列表  已通过待分配， 已分配
	 * 专家类型：1-普通专家，2-资深专家
	 * @param reqVO
	 * @return
	 */
	@AutoLog(value = "NIKE团队-初审案例分配/入围案例分配列表")
	@ApiOperation(value="NIKE团队-初审案例分配/入围案例分配列表", notes="查询初审案例分配/入围案例分配列表")
	@PostMapping(value = "/getProjectAssignList")
	public Result<RespProjectAssignmentListVO> getProjectAssignList(@RequestBody ReqProjectAssignmentListVO reqVO){
		return sportsProjectService.getProjectAssignList(reqVO);
	}

	@AutoLog(value = "NIKE团队-初审争议/入围争议案例分配列表")
	@ApiOperation(value="NIKE团队-初审争议/入围争议案例分配列表", notes="查询初审争议/入围争议案例分配列表")
	@PostMapping(value = "/getDisputeList")
	public Result<RespDisputeListVO> getDisputeList(@RequestBody DisputeListReqVO reqVO){
		return sportsProjectService.getDisputeList(reqVO);
	}

	@AutoLog(value = "NIKE团队-初审打分结果")
	@ApiOperation(value="NIKE团队-初审打分结果", notes="初审打分结果")
	@PostMapping(value = "/getFirstAuditScoreList")
	public Result<AuditScoreListRespVO> getFirstAuditScoreList(@RequestBody AuditScoreListReqVO reqVO){
		return sportsProjectService.getFirstAuditScoreList(reqVO);
	}

	@AutoLog(value = "NIKE团队-获奖案例管理")
	@ApiOperation(value="NIKE团队-获奖案例管理", notes="初审打分结果/已入围案例列表")
	@PostMapping(value = "/winList")
	public Result<AuditScoreListRespVO> winList(@RequestBody AuditScoreListReqVO reqVO){
		return sportsProjectService.getWinList(reqVO);
	}

	/**
	 * 求平均分， 可手动调用也可JOB调用
	 * @param judgeType  1-初审，2-资深
	 */
	@PostMapping(value = "/averageScore")
	public void averageScore(@RequestParam(value = "judgeType") String judgeType,
							 @RequestParam(value = "year", required = false) Integer year){
		 sportsProjectService.averageScore(judgeType, year);
	}

	/**
	 * 普通专家、资升专家案例分配
	 *  1.需提取一线体育老师普通专家案例分配的总评分前200名  校长普通专家案例分配的总评分前15名
	 *  2.专家角色为资升专家
	 *  judgeType 1-普通专家，2-资深专家 3-初审争议，4-终审争议
	 * @return
	 */
	@AutoLog(value = "案例分配")
	@ApiOperation(value="案例分配", notes="案例分配")
	@PostMapping(value = "/assignment")
	public Result<?> projectAssignment(@RequestBody AssignmentReqVO reqVO, HttpServletRequest request){
		String username = JwtUtil.getUserNameByToken(request);
		return sportsProjectService.projectAssignment(reqVO, username);
	}

	/**
	 * 更新所有案例的评审状态 定时任务
	 * @param projectId
	 * @return
	 */
//	@AutoLog(value = "更新所有案例的评审状态 定时任务")
//	@ApiOperation(value="定时任务", notes="定时任务")
//	@GetMapping(value = "/updProjectStatus")
//	public Result<?> updProjectStatus(@RequestParam(name="projectId",required=false) String projectId,
//									  @RequestParam(name="reviewType") String reviewType){
//		return sportsProjectService.updateProjectStatus(projectId, reviewType);
//	}

	/**
	 * 案例淘汰/通过   一审完成后：一线体育老师top200, 校长top15 ;二审完成后，一线体育老师 top100，校长 top10
	 * @param operationVO  actionType 1-通过 2-淘汰, 3-案例入围top200/top15 4-案例获奖 TOP100/TOP10
	 * @param request
	 * @return
	 */
	@AutoLog(value = "案例淘汰/通过/入围top200/获奖")
	@ApiOperation(value="案例淘汰/通过/入围/获奖", notes="案例淘汰/通过/入围/获奖")
	@PostMapping(value = "/operation")
	public Result<?> operation(@RequestBody OperationVO operationVO,
								HttpServletRequest request){
		String username = JwtUtil.getUserNameByToken(request);
		return sportsProjectService.operation(operationVO, username);
	}

	@AutoLog(value = "群发邮件通知")
	@ApiOperation(value="群发邮件通知", notes="群发邮件通知")
	@GetMapping(value = "/sendMsgByEmail")
	public Result<?> sendMsgByEmail(){
		return sportsProjectService.sendMsgByEmail();
	}

	@AutoLog(value = "群发短信模板通知")
	@ApiOperation(value="群发短信模板通知", notes="群发短信模板通知")
	@GetMapping(value = "/sendMsgByTemplate")
	public Result<?> sendMsgByTemplate(){
		return sportsProjectService.sendMsgByTemplate();
	}


	@AutoLog(value = "TOP200求系数")
	@ApiOperation(value="TOP200求系数", notes="TOP200求系数")
	@GetMapping(value = "/getCoefficient")
	public Result<?> getCoefficient(){
		return sportsProjectService.getCoefficient();
	}

}
